Next: 3.18.2 DS390 Memory Model Up: 3.18 Memory Models Previous: 3.18 Memory Models Contents Index
Subsections

- 3.18.1.1 Small, Medium, Large and Huge
- 3.18.1.2 External Stack

##
3.18.1 MCS51 Memory Models

### 3.18.1.1 Small, Medium, Large and Huge

SDCC allows four memory models for MCS51 code, small, medium, large and huge. Modules compiled with different memory models should never be combined together or the results would be unpredictable. The library routines supplied with the compiler are compiled as small, medium and large. The compiled library modules are contained in separate directories as small, medium and large so that you can link to the appropriate set.

When the medium, large or huge model is used all variables declared without a storage class will be allocated into the external ram, this includes all parameters and local variables (for non-reentrant functions). Medium model uses pdata and large and huge models use xdata. When the small model is used variables without storage class are allocated in the internal ram.

The huge model compiles all functions as banked4.1.3 and is otherwise equal to large for now. All other models compile the functions without bankswitching by default.

Judicious usage of the processor specific storage classes and the 'reentrant' function type will yield much more efficient code, than using the large model. Several optimizations are disabled when the program is compiled using the large model, it is therefore recommended that the small model be used unless absolutely required.

###
3.18.1.2 External Stack

The external stack (--xstack option) is located in pdata memory (usually at the start of the external ram segment) and uses all unused space in pdata (max. 256 bytes). When --xstack option is used to compile the program, the parameters and local variables of all reentrant functions are allocated in this area. This option is provided for programs with large stack space requirements. When used with the --stack-auto option, all parameters and local variables are allocated on the external stack (note: support libraries will need to be recompiled with the same options. There is a predefined target in the library makefile).

The compiler outputs the higher order address byte of the external ram segment into port P2 (see also section 4.1), therefore when using the External Stack option, this port may not be used by the application program.

Next: 3.18.2 DS390 Memory Model Up: 3.18 Memory Models Previous: 3.18 Memory Models Contents Index